/*
 * @Author: rock
 * @Date: 2025-04-19 08:50:59
 * @LastEditors: rock
 * @LastEditTime: 2025-04-19 09:15:00
 * @FilePath: /006logger/include/logqueue.h
 * @Description:
 *
 * Copyright (c) 2025 by rock, All Rights Reserved.
 */
#ifndef _LOGQUEUE_H
#define _LOGQUEUE_H

#include <iostream>
#include <mutex>
#include <condition_variable>
#include <string>
#include <queue>

class LogQueue
{
public:
    // 向队列中添加日志消息
    void push(const std::string &msg);

    // 任务队列pop日志消息
    bool pop(std::string &msg);

    // 关闭队列, 通知消费者等待消息
    void shutdown();

private:
    std::queue<std::string> queue_; // 数据队列
    std::mutex mtx;                 // 保证线程安全
    std::condition_variable cond;   // 保证线程同步
    bool is_shutdown = false;       // 默认情况下关闭是false, 开启状态
};

#endif